package com.colorlight.cloud.xm.entity.po;

import com.colorlight.cloud.gateway.api.message.constraint.basics.object.Trans;
import com.colorlight.iot.proto.xm.entity.XmEntity;
import com.google.protobuf.ByteString;
import lombok.*;

import java.util.Objects;

/**
 * @author Demon
 * @description 加密的细节
 * @date 6/5/2024  上午8:52
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AuthorizationDetail implements Trans<AuthorizationDetail, XmEntity.AuthorizationDetail> {
	/**
	 * 发送卡序号
	 * 加密密码
	 * 授权截止时间 hex 通过 aes加密后的string
	 * 厂商、密码等信息 hex 通过aes 加密后的string
	 */
	private byte[] file1;
	private byte[] file2;
	
	@Override
	public XmEntity.AuthorizationDetail toProto() {
		XmEntity.AuthorizationDetail.Builder builder = XmEntity.AuthorizationDetail.newBuilder();
		if (Objects.nonNull(file1)) {
			builder.setFile1(ByteString.copyFrom(file1));
		}
		if (Objects.nonNull(file2)) {
			builder.setFile2(ByteString.copyFrom(file2));
		}
		return builder.build();
	}
	
	@Override
	public AuthorizationDetail formProto(XmEntity.AuthorizationDetail authorizationDetail) {
		this.setFile1(Objects.nonNull(authorizationDetail.getFile1()) ? authorizationDetail.getFile1().toByteArray() : null);
		this.setFile2(Objects.nonNull(authorizationDetail.getFile2()) ? authorizationDetail.getFile2().toByteArray() : null);
		return this;
	}
}
